package keeto.com.vn.bms.ui.adapter;

import java.util.ArrayList;

import keeto.com.vn.bms.model.InfoMessegerModel;
import keeto.com.vn.bms.ui.activity.R;
import keeto.com.vn.bms.utils.Utils;

import android.content.Context;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class InfoMessegerAdapter extends BaseAdapter {

	private Context ctx;
	private ArrayList<InfoMessegerModel> mArrayList;
	private LayoutInflater mInflater;

	public InfoMessegerAdapter(Context context,
			ArrayList<InfoMessegerModel> ArrayList) {
		super();
		this.ctx = context;
		this.mArrayList = ArrayList;
		this.mInflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mArrayList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return mArrayList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder;
		if (convertView == null){
			convertView = mInflater.inflate(R.layout.item_info_messeger_layout,null);
			holder = new ViewHolder();
			holder.tvMsgPermisstion = (TextView)convertView.findViewById(R.id.tv_item_info_msg_permission);
			holder.tvMsgContent = (TextView)convertView.findViewById(R.id.tv_item_info_msg_content);
			holder.tvmsgTime = (TextView)convertView.findViewById(R.id.tv_item_info_msg_time);
			convertView.setTag(holder);
		}else{
			holder = (ViewHolder) convertView.getTag();
		}
		
			holder.tvMsgPermisstion.setText(mArrayList.get(position).getFullName());
		
		holder.tvMsgContent.setText(mArrayList.get(position).getMsgContent());
		holder.tvmsgTime.setText(Utils.convertTime(mArrayList.get(position).getMsgTime()));
		if (mArrayList.get(position).isRead()){
			holder.tvMsgContent.setTextColor(ctx.getResources().getColor(R.color.hint_color));
			holder.tvMsgContent.setTypeface(null, Typeface.NORMAL);
		}else{
			holder.tvMsgContent.setTextColor(ctx.getResources().getColor(R.color.tv_color));
			holder.tvMsgContent.setTypeface(null, Typeface.BOLD);
		}
		
		return convertView;
	}

	class ViewHolder{
		private TextView tvMsgPermisstion;
		private TextView tvMsgContent;
		private TextView tvmsgTime;
	}

}
